package com.cqeec.ui;

import java.awt.Dialog;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;

import com.cqeec.util.Ascii2Native;

/**
 * 
 * @author HuaL
 * @description 关于我们窗体
 */
public class AboutFrame extends Dialog {
	public AboutFrame(JFrame owner, String title, boolean modal) {
		super(owner, title, modal);
		setBounds(0, 0, 360, 250);
		setLayout(null);
		setLocationRelativeTo(null);
		JLabel aboutImg = new JLabel();
		
		ImageIcon image = new ImageIcon("Image\\about.jpg");
		aboutImg.setOpaque(true);
		aboutImg.setIcon(image);
		aboutImg.setBounds(0, 20, 360, 80);
		add(aboutImg);
		
		
		JLabel project = new JLabel();
		project.setText(Ascii2Native.ascii2Native(loadProperty().getProperty("project")));
		JLabel company = new JLabel();
		company.setText(Ascii2Native.ascii2Native(loadProperty().getProperty("company")));
		JLabel copyright = new JLabel();
		copyright.setText("copyright © 2016 By CQEEC Allrights Reserved");
		add(project);
		project.setBounds(92, 120, 180, 25);
		add(company);
		company.setBounds(80, 150, 260, 25);
		add(copyright);
		copyright.setBounds(45, 180, 360, 25);
		JButton btn = new JButton();
		image = new ImageIcon("Image\\ok.jpg");
		btn.setIcon(image);
		add(btn);
		btn.setBounds(155, 211, 71, 28);
		btn.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
				AboutFrame.this.dispose();
			}
		});
		setResizable(false);
		addWindowListener(new WindowAdapter() {
			public void windowClosing(WindowEvent e) {
				// TODO Auto-generated method stub
//				((Dialog) e.getWindow()).dispose();
				AboutFrame.this.dispose();
			}
		});
	}

	/**
	 * 读取配置文件
	 */
	public Properties loadProperty() {
		Properties prop = new Properties();
		try {
			InputStream is = AboutFrame.class
					.getResourceAsStream("/about.properties");
			prop.load(is);
			is.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return prop;
	}
}
